package com.okaixz.client.controller;

import com.okaixz.client.model.dto.HotArticleDto;
import com.okaixz.common.annotation.Anonymous;
import com.okaixz.common.client.Result;
import com.okaixz.common.core.controller.BaseController;
import com.okaixz.common.core.page.TableDataInfo;
import com.okaixz.manager.article.domain.CArticle;
import com.okaixz.manager.article.service.ICArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * AI写作案例Controller
 *
 * @author ruoyi
 * @date 2024-08-18
 */
@RestController
@RequestMapping("/article")
@Api("文章管理")
@Anonymous
public class ClientCArticleController extends BaseController
{
    @Autowired
    private ICArticleService cArticleService;

    /**
     * 查询AI写作案例列表
     */
    @GetMapping("/list")
    @ApiOperation("获取文章列表")
    public TableDataInfo list(CArticle cArticle)
    {
        startPage();
        cArticle.setStatus(1l);
        List<CArticle> list = cArticleService.selectCArticleList(cArticle);
        return getDataTable(list);
    }
    /**
     * 查询热门文章
     */
    @GetMapping("/hot/{tabId}")
    @ApiOperation("获取文章列表")
    public Result<HotArticleDto> hotList(@PathVariable("tabId") Long tabId)
    {
        HotArticleDto hotArticleDto=new HotArticleDto();
        CArticle cArticle=new CArticle();
        cArticle.setStatus(1l);
        cArticle.setTabId(16l);//站内动态
        TableDataInfo table1 = list(cArticle);
        hotArticleDto.setList1((List<CArticle>) table1.getRows());

        cArticle.setTabId(tabId);//相关文章
        TableDataInfo table2 = list(cArticle);
        hotArticleDto.setList2((List<CArticle>) table2.getRows());

        cArticle.setTabId(null);
        List<CArticle> list3 = cArticleService.selectHotArticle(cArticle);//热门文章
        hotArticleDto.setList3(list3);

        return Result.success(hotArticleDto);
    }


    /**
     * 获取AI写作案例详细信息
     */
    @GetMapping(value = "/{id}")
    public Result<CArticle> getInfo(@PathVariable("id") Long id)
    {
        return Result.success(cArticleService.selectCArticleById(id));
    }


}
